# 协程 用代码切换io操作，欺骗单线程cpu提高效率，实现并发
import time

import gevent
from gevent import monkey

monkey.patch_all()


def func1():
    print('func1')
    time.sleep(2)
    print('func1')


def func2():
    print('func2')
    time.sleep(3)
    print('func2')


if __name__ == '__main__':
    start_time = time.time()
    g1 = gevent.spawn(func1)  # 传入函数名，自动帮你加括号调用
    g2 = gevent.spawn(func2)
    g1.join()
    g2.join()  # 等待被检查的任务执行完毕，再往后执行

    print(time.time() - start_time)
